3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 use MediaWiki\MediaWikiServices
;
24 * Form to edit user preferences.
28 class PreferencesFormOOUI
extends OOUIHTMLForm
{
29 // Override default value from HTMLForm
30 protected $mSubSectionBeforeFields = false;
32 private $modifiedUser;
37 public function setModifiedUser( $user ) {
38 $this->modifiedUser
= $user;
44 public function getModifiedUser() {
45 if ( $this->modifiedUser
=== null ) {
46 return $this->getUser();
48 return $this->modifiedUser
;
53 * Get extra parameters for the query string when redirecting after
58 public function getExtraSuccessRedirectParameters() {
66 function wrapForm( $html ) {
67 $html = Xml
::tags( 'div', [ 'id' => 'preferences' ], $html );
69 return parent
::wrapForm( $html );
75 function getButtons() {
76 if ( !MediaWikiServices
::getInstance()
77 ->getPermissionManager()
78 ->userHasAnyRight( $this->getModifiedUser(), 'editmyprivateinfo', 'editmyoptions' )
83 $html = parent
::getButtons();
85 if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
86 $t = $this->getTitle()->getSubpage( 'reset' );
88 $html .= new OOUI\
ButtonWidget( [
90 'id' => 'mw-prefs-restoreprefs',
91 'label' => $this->msg( 'restoreprefs' )->text(),
92 'href' => $t->getLinkURL(),
93 'flags' => [ 'destructive' ],
97 $html = Xml
::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
104 * Separate multi-option preferences into multiple preferences, since we
105 * have to store them separately
109 function filterDataForSubmit( $data ) {
110 foreach ( $this->mFlatFields
as $fieldname => $field ) {
111 if ( $field instanceof HTMLNestedFilterable
) {
112 $info = $field->mParams
;
113 $prefix = $info['prefix'] ??
$fieldname;
114 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
115 $data["$prefix$key"] = $value;
117 unset( $data[$fieldname] );
124 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
125 $layout = parent
::wrapFieldSetSection( $legend, $section, $attributes, $isRoot );
127 $layout->addClasses( [ 'mw-prefs-fieldset-wrapper' ] );
128 $layout->removeClasses( [ 'oo-ui-panelLayout-framed' ] );
134 * Get the whole body of the form.
139 foreach ( $this->mFieldTree
as $key => $val ) {
140 if ( !is_array( $val ) ) {
141 wfDebug( __METHOD__
. " encountered a field not attached to a section: '$key'" );
144 $label = $this->getLegend( $key );
146 $this->getHeaderText( $key ) .
147 $this->displaySection(
148 $this->mFieldTree
[$key],
150 "mw-prefsection-$key-"
152 $this->getFooterText( $key );
154 $tabPanels[] = new OOUI\
TabPanelLayout( 'mw-prefsection-' . $key, [
155 'classes' => [ 'mw-htmlform-autoinfuse-lazy' ],
157 'content' => new OOUI\
FieldsetLayout( [
158 'classes' => [ 'mw-prefs-section-fieldset' ],
159 'id' => "mw-prefsection-$key",
163 'content' => new OOUI\
HtmlSnippet( $content )
172 $indexLayout = new OOUI\
IndexLayout( [
175 'autoFocus' => false,
176 'classes' => [ 'mw-prefs-tabs' ],
178 $indexLayout->addTabPanels( $tabPanels );
180 return new OOUI\
PanelLayout( [
183 'classes' => [ 'mw-prefs-tabs-wrapper' ],
184 'content' => $indexLayout
189 * Get the "<legend>" for a given section key. Normally this is the
190 * prefs-$key message but we'll allow extensions to override it.
194 function getLegend( $key ) {
195 $legend = parent
::getLegend( $key );
196 Hooks
::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
201 * Get the keys of each top level preference section.
202 * @return string[] List of section keys
204 function getPreferenceSections() {
205 return array_keys( array_filter( $this->mFieldTree
, 'is_array' ) );